public class ImagePickerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<ImageObject> iageObjectList;
	private OnChooseistener mOnChooseListener;

	//构造函数
    public ImagePickerAdapter(Context context, List<ImageObject> imageObjects) {
        this.mContext = context;
        this.imageObjectList = imageObjects;
    } 

    @Override
    public int getItemViewType(int position) {
        return ItemType.ITEM_TYPE_IMAGE;
    }

    @Override
    public int getItemCount() {
        return imageObjectList.size();
    }

    //外部获取imageObject
    public ImageObject getImageObject(int position) {
        return imageObjectList.get(position);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View  view = LayoutInflater.from(mContext).inflate(R.layout.item_recyclerview_image, null);
        return new ImageHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
            ImageHolder imageHolder = (ImageHolder) holder;
            ImageObject imageObject = getImageObject(position);
            String imagePath = imageObject.getImagePath();
            imageHolder.mImageCheck.setVisibility(View.VISIBLE);
            //根据已选管理器，展示对勾
            if (SelectionManager.getInstance().isImageSelect(imagePath)) {
               imageHolder.mImageView.setColorFilter(Color.parseColor("#77000000"));
               imageHolder.mImageCheck.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.icon_image_checked));
            } else {
               imageHolder.mImageView.setColorFilter(null);
               imageHolder.mImageCheck.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.icon_image_check));
            }  
			//展示图片
		    Glide.with(context).load(imagePath).into(imageHolder.mImageView);
			//选择事件
		    imageHolder.mImageCheck.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					mOnChooseListener.onImageChoose(view, position);
				}
			});
    }

    //图片holder
    class ImageHolder extends RecyclerView.ViewHolder {
        private SquareImageView mImageView;
        private ImageView mImageCheck;
        public ImageHolder(View itemView) {
            super(itemView);
            mImageView = itemView.findViewById(R.id.iv_item_image);
            mImageCheck = itemView.findViewById(R.id.iv_item_check);
        }
    }

    //adapter中点击回调给外部
	public interface OnChooseistener {
        void onImageChoose(View view, int position);
    }
    public void setOnChooseistener(OnChooseistener onChooseistener) {
        this.mOnChooseListener = mOnChooseListener;
    }

   
}
